﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MinhTuan;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
public partial class PicCapcha : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Tao mot doi tuong anh
        Bitmap objmap = new System.Drawing.Bitmap(80, 25);
        Graphics objgraphics = System.Drawing.Graphics.FromImage(objmap);
        //set nen cho anh
        objgraphics.Clear(Color.Green);
        Random rand = new Random();
        //chuoi font
        string[] fonts = { "Arial Black", "Lucida Sans Unicode", "Comic Sans MS" };
        string  strcapcha = Access.MakeCapcha();
            Session.Add("strcapcha", strcapcha);
            for (int i = 0; i < strcapcha.Length; i++)
            {
                Font font = new Font(fonts[rand.Next(fonts.Length)], 10, FontStyle.Italic | FontStyle.Regular);
                SizeF size = objgraphics.MeasureString(strcapcha[i].ToString(), font);
                objgraphics.DrawString(strcapcha[i].ToString(), font, Brushes.White, i * size.Width + 2, rand.Next(2, 10));
                font.Dispose();
            }
        //set content type and return image
            Response.ContentType = "image/GIF";
            objmap.Save(Response.OutputStream, ImageFormat.Gif);
            objmap.Dispose();
            objgraphics.Dispose();
    }
}
